package net.orange.framework.validator;

import net.orange.architecture.validator.IObjectValidator;
import net.orange.framework.model.Department;

/**
 * Validation : Department's parent can't be himself.
 */
public class DepartmentParentValidator extends FrameworkValidator implements
		IObjectValidator {

	/**
	 * The target department.
	 */
	private Department department;

	/**
	 * Disabled the default contractor.
	 */
	@SuppressWarnings("unused")
	private DepartmentParentValidator() throws Exception {

	}

	/**
	 * Constructor with department object to initialize the validation.
	 * 
	 * @param department
	 *            The target department.
	 */
	public DepartmentParentValidator(Department department) throws Exception {
		this.department = department;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.validator.ObjectValidator#check()
	 */
	@Override
	public boolean check() throws Exception {
		return (department.getParent() == null || department.getParent()
				.getPk() != department.getPk());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.validator.ObjectValidator#getMessage()
	 */
	@Override
	public String getMessage() {
		return message.get("error2_dept_07");
	}

}
